#pragma once

#include "modules/common_msgs/sensor_msgs/pointcloud.pb.h"
#include "modules/drivers/lidar/orin_hesai/proto/lidar_hesai_config.pb.h"

#include "cyber/cyber.h"
#include "modules/drivers/lidar/orin_hesai/common/data_buffer.h"
#include "modules/drivers/lidar/orin_hesai/parser/lidar_parser.h"
#include "modules/drivers/lidar/orin_hesai/publisher/lidar_publisher.h"
#include "modules/drivers/lidar/orin_hesai/receiver/lidar_receiver.h"

#define PACKET_BUFFER_SIZE 512
#define FRAME_BUFFER_SIZE 10

namespace apollo {
namespace drivers {
namespace lidar_hesai {

using apollo::cyber::Node;
using apollo::cyber::Writer;
using apollo::drivers::PointCloud;
using apollo::drivers::lidar_hesai::Config;

class LidarHesaiDriver {
 public:
  LidarHesaiDriver(const std::shared_ptr<cyber::Node>& node,
                   const ::apollo::drivers::lidar_hesai::Config& config)
      : node_(node), config_(config) {}

  bool Init();
  ~LidarHesaiDriver();
  
 private:
  std::shared_ptr<cyber::Node> node_;
  Config config_;
  std::shared_ptr<CircularQueueBuffer<LidarPacket>> packet_buffer_;
  std::shared_ptr<CircularQueueBuffer<PointCloud>> pc_buffer_;

  std::shared_ptr<LidarReceiver> receiver_;
  std::shared_ptr<LidarParser> parser_;
  std::shared_ptr<LidarPublisher> publisher_;

  std::thread thread_receiver_;
  std::thread thread_parser_;
  std::thread thread_publisher_;
};
}  // namespace lidar_hesai
}  // namespace drivers
}  // namespace apollo
